#ifndef DATABASE_H
#define DATABASE_H

#include "common.h"
#include "sqlite3.h"

// 定义列索引常量（避免硬编码）
namespace ColumnIndex {
    constexpr int ID                  = 0;
    constexpr int DM_DATA_COMPANY_ID  = 1;
    constexpr int ROAD_TYPE           = 2;
    constexpr int DEVICE_ID           = 3;
    constexpr int SRC_PIC_DIR         = 4;
    constexpr int RES_PIC_DIR         = 5;
    constexpr int PICTURE_NAME        = 6;
    constexpr int COLLECT_TIME        = 7;
    constexpr int LONGITUDE           = 8;
    constexpr int LATITUDE            = 9;
    constexpr int SPEED               = 10;
    constexpr int AZIMUTH             = 11;
    constexpr int RES                 = 12;
    constexpr int ALGORITHM_TIME      = 13;
    constexpr int CAMERA_TYPE         = 14;
    constexpr int AUTO_APPROVAL       = 15;
    constexpr int GCJ_DAMAGE          = 16;
    constexpr int PIC_RESOLUTION      = 17;
    constexpr int SCENE_ID            = 18;
    constexpr int CAMERA_ANTENNA_ANGLE= 19;
    constexpr int CAMERA_DISTANCE     = 20;
    constexpr int CAMERA_VEHICLE_ANGLE= 21;
    constexpr int GPS_STATUS          = 22;
    constexpr int PITCH               = 23;
}

class DataBase
{
public:
    DataBase();

public:
    int initDeviceCodeDB();

    int deviceCodeSelect(QString &deviceId);

    int drDataCreate();

    int drDataInsert(QQueue<DISEASE_INFO> &p_diseInfoQueue);

    int drDataSelect(int p_id, QQueue<DISEASE_INFO> &p_diseInfoQueue);

    int drDataOtherSelect(int &all, int &valid, int &upload, int maxUploadId);

private:
    int dbOpen(const string dbpath, sqlite3 **db);

    int dbExec(sqlite3 *p_db, const string str_sql, char *p_data);

    int dbClose(sqlite3 *p_db);

};

#endif // DATABASE_H
